package cn.wdm.ymcc.service.impl;

import cn.wdm.ymcc.service.ITokenService;
import cn.wdm.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TokenServiceImpl implements ITokenService {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public String createPreventRepeatToken(String courseId) {
        //当前的登录人
        Long loginId = 1L;
        //生成token
        String token = StrUtils.getRandomString(10);
        String key=courseId+":"+loginId;//1,3:1
        System.out.println(key+"----------------------");
        redisTemplate.opsForValue().set(key,token,10, TimeUnit.MINUTES);
        return token;
    }
}
